$OpenBSD: patch-Modules_FindTCL_cmake,v 1.13 2016/11/28 09:15:13 dcoppa Exp $
--- Modules/FindTCL.cmake.orig	Fri Nov 11 15:37:13 2016
+++ Modules/FindTCL.cmake	Fri Nov 25 22:31:45 2016
@@ -48,19 +48,36 @@ include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindFrameworks.
 include(${CMAKE_CURRENT_LIST_DIR}/FindTclsh.cmake)
 include(${CMAKE_CURRENT_LIST_DIR}/FindWish.cmake)
 
+set(MODTCL_VERSION $ENV{MODTCL_VERSION})
+set(MODTK_VERSION $ENV{MODTK_VERSION})
+set(MODTCL_INCDIR $ENV{MODTCL_INCDIR})
+set(MODTK_INCDIR $ENV{MODTK_INCDIR})
+set(MODTCL_LIB $ENV{MODTCL_LIB})
+set(MODTK_LIB $ENV{MODTK_LIB})
+set(MODTCL_LIBDIR $ENV{MODTCL_LIBDIR})
+set(MODTK_LIBDIR $ENV{MODTK_LIBDIR})
+
 if(TCLSH_VERSION_STRING)
   set(TCL_TCLSH_VERSION "${TCLSH_VERSION_STRING}")
 else()
   get_filename_component(TCL_TCLSH_PATH "${TCL_TCLSH}" PATH)
   get_filename_component(TCL_TCLSH_PATH_PARENT "${TCL_TCLSH_PATH}" PATH)
-  string(REGEX REPLACE
-    "^.*tclsh([0-9]\\.*[0-9]).*$" "\\1" TCL_TCLSH_VERSION "${TCL_TCLSH}")
+  if(MODTCL_VERSION)
+    set(TCL_TCLSH_VERSION "${MODTCL_VERSION}")
+  else(MODTCL_VERSION)
+    string(REGEX REPLACE
+      "^.*tclsh([0-9]\\.*[0-9]).*$" "\\1" TCL_TCLSH_VERSION "${TCL_TCLSH}")
+  endif(MODTCL_VERSION)
 endif()
 
 get_filename_component(TK_WISH_PATH "${TK_WISH}" PATH)
 get_filename_component(TK_WISH_PATH_PARENT "${TK_WISH_PATH}" PATH)
-string(REGEX REPLACE
-  "^.*wish([0-9]\\.*[0-9]).*$" "\\1" TK_WISH_VERSION "${TK_WISH}")
+if(MODTK_VERSION)
+  set(TK_WISH_VERSION "${MODTK_VERSION}")
+else(MODTK_VERSION)
+  string(REGEX REPLACE
+    "^.*wish([0-9]\\.*[0-9]).*$" "\\1" TK_WISH_VERSION "${TK_WISH}")
+endif(MODTK_VERSION)
 
 get_filename_component(TCL_INCLUDE_PATH_PARENT "${TCL_INCLUDE_PATH}" PATH)
 get_filename_component(TK_INCLUDE_PATH_PARENT "${TK_INCLUDE_PATH}" PATH)
@@ -75,19 +92,37 @@ get_filename_component(TK_LIBRARY_PATH_PARENT "${TK_LI
 string(REGEX REPLACE
   "^.*tk([0-9]\\.*[0-9]).*$" "\\1" TK_LIBRARY_VERSION "${TK_LIBRARY}")
 
-set(TCLTK_POSSIBLE_LIB_PATHS
-  "${TCL_INCLUDE_PATH_PARENT}/lib"
-  "${TK_INCLUDE_PATH_PARENT}/lib"
-  "${TCL_LIBRARY_PATH}"
-  "${TK_LIBRARY_PATH}"
-  "${TCL_TCLSH_PATH_PARENT}/lib"
-  "${TK_WISH_PATH_PARENT}/lib"
-  /usr/local/lib/tcl/tcl8.5
-  /usr/local/lib/tcl/tk8.5
-  /usr/local/lib/tcl/tcl8.4
-  /usr/local/lib/tcl/tk8.4
-  )
+set(TCLTK_OPENBSD_LIB_PATHS)
 
+if(MODTCL_LIBDIR)
+  list(APPEND TCLTK_OPENBSD_LIB_PATHS "${MODTCL_LIBDIR}")
+endif()
+
+if(MODTK_LIBDIR)
+  list(APPEND TCLTK_OPENBSD_LIB_PATHS "${MODTK_LIBDIR}")
+endif()
+
+if(NOT "${TCLTK_OPENBSD_LIB_PATHS}" STREQUAL "")
+  set(TCLTK_POSSIBLE_LIB_PATHS
+    "${TCLTK_OPENBSD_LIB_PATHS}"
+    )
+else()
+  set(TCLTK_POSSIBLE_LIB_PATHS
+    "${TCL_INCLUDE_PATH_PARENT}/lib"
+    "${TK_INCLUDE_PATH_PARENT}/lib"
+    "${TCL_LIBRARY_PATH}"
+    "${TK_LIBRARY_PATH}"
+    "${TCL_TCLSH_PATH_PARENT}/lib"
+    "${TK_WISH_PATH_PARENT}/lib"
+    ${LOCALBASE}/lib/tcl/tcl8.6
+    ${LOCALBASE}/lib/tcl/tk8.6
+    ${LOCALBASE}/lib/tcl/tcl8.5
+    ${LOCALBASE}/lib/tcl/tk8.5
+    ${LOCALBASE}/lib/tcl/tcl8.4
+    ${LOCALBASE}/lib/tcl/tk8.4
+    )
+endif()
+
 if(WIN32)
   get_filename_component(
     ActiveTcl_CurrentVersion
@@ -107,31 +142,47 @@ if(WIN32)
     )
 endif()
 
-find_library(TCL_LIBRARY
-  NAMES
-  tcl
-  tcl${TCL_LIBRARY_VERSION} tcl${TCL_TCLSH_VERSION} tcl${TK_WISH_VERSION}
-  tcl86 tcl8.6
-  tcl85 tcl8.5
-  tcl84 tcl8.4
-  tcl83 tcl8.3
-  tcl82 tcl8.2
-  tcl80 tcl8.0
-  PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
-  )
+if(MODTCL_LIB)
+  find_library(TCL_LIBRARY
+    NAMES
+    ${MODTCL_LIB}
+    PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+    )
+else(MODTCL_LIB)
+  find_library(TCL_LIBRARY
+    NAMES
+    tcl
+    tcl${TCL_LIBRARY_VERSION} tcl${TCL_TCLSH_VERSION} tcl${TK_WISH_VERSION}
+    tcl86 tcl8.6
+    tcl85 tcl8.5
+    tcl84 tcl8.4
+    tcl83 tcl8.3
+    tcl82 tcl8.2
+    tcl80 tcl8.0
+    PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+    )
+endif(MODTCL_LIB)
 
-find_library(TK_LIBRARY
-  NAMES
-  tk
-  tk${TK_LIBRARY_VERSION} tk${TCL_TCLSH_VERSION} tk${TK_WISH_VERSION}
-  tk86 tk8.6
-  tk85 tk8.5
-  tk84 tk8.4
-  tk83 tk8.3
-  tk82 tk8.2
-  tk80 tk8.0
-  PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
-  )
+if(MODTK_LIB)
+  find_library(TK_LIBRARY
+    NAMES
+    ${MODTK_LIB}
+    PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+    )
+else(MODTK_LIB)
+  find_library(TK_LIBRARY
+    NAMES
+    tk
+    tk${TK_LIBRARY_VERSION} tk${TCL_TCLSH_VERSION} tk${TK_WISH_VERSION}
+    tk86 tk8.6
+    tk85 tk8.5
+    tk84 tk8.4
+    tk83 tk8.3
+    tk82 tk8.2
+    tk80 tk8.0
+    PATHS ${TCLTK_POSSIBLE_LIB_PATHS}
+    )
+endif(MODTK_LIB)
 
 CMAKE_FIND_FRAMEWORKS(Tcl)
 CMAKE_FIND_FRAMEWORKS(Tk)
@@ -155,30 +206,46 @@ if(Tk_FRAMEWORKS)
   endif()
 endif()
 
-set(TCLTK_POSSIBLE_INCLUDE_PATHS
-  "${TCL_LIBRARY_PATH_PARENT}/include"
-  "${TK_LIBRARY_PATH_PARENT}/include"
-  "${TCL_INCLUDE_PATH}"
-  "${TK_INCLUDE_PATH}"
-  ${TCL_FRAMEWORK_INCLUDES}
-  ${TK_FRAMEWORK_INCLUDES}
-  "${TCL_TCLSH_PATH_PARENT}/include"
-  "${TK_WISH_PATH_PARENT}/include"
-  /usr/include/tcl${TK_LIBRARY_VERSION}
-  /usr/include/tcl${TCL_LIBRARY_VERSION}
-  /usr/include/tcl8.6
-  /usr/include/tcl8.5
-  /usr/include/tcl8.4
-  /usr/include/tcl8.3
-  /usr/include/tcl8.2
-  /usr/include/tcl8.0
-  /usr/local/include/tcl8.6
-  /usr/local/include/tk8.6
-  /usr/local/include/tcl8.5
-  /usr/local/include/tk8.5
-  /usr/local/include/tcl8.4
-  /usr/local/include/tk8.4
-  )
+set(TCLTK_OPENBSD_INCLUDE_PATHS)
+
+if(MODTCL_INCDIR)
+  list(APPEND TCLTK_OPENBSD_INCLUDE_PATHS "${MODTCL_INCDIR}")
+endif()
+
+if(MODTK_INCDIR)
+  list(APPEND TCLTK_OPENBSD_INCLUDE_PATHS "${MODTK_INCDIR}")
+endif()
+
+if(NOT "${TCLTK_OPENBSD_INCLUDE_PATHS}" STREQUAL "")
+  set(TCLTK_POSSIBLE_INCLUDE_PATHS
+    "${TCLTK_OPENBSD_INCLUDE_PATHS}"
+    )
+else()
+  set(TCLTK_POSSIBLE_INCLUDE_PATHS
+    "${TCL_LIBRARY_PATH_PARENT}/include"
+    "${TK_LIBRARY_PATH_PARENT}/include"
+    "${TCL_INCLUDE_PATH}"
+    "${TK_INCLUDE_PATH}"
+    ${TCL_FRAMEWORK_INCLUDES}
+    ${TK_FRAMEWORK_INCLUDES}
+    "${TCL_TCLSH_PATH_PARENT}/include"
+    "${TK_WISH_PATH_PARENT}/include"
+    /usr/include/tcl${TK_LIBRARY_VERSION}
+    /usr/include/tcl${TCL_LIBRARY_VERSION}
+    /usr/include/tcl8.6
+    /usr/include/tcl8.5
+    /usr/include/tcl8.4
+    /usr/include/tcl8.3
+    /usr/include/tcl8.2
+    /usr/include/tcl8.0
+    ${LOCALBASE}/include/tcl8.6
+    ${LOCALBASE}/include/tk8.6
+    ${LOCALBASE}/include/tcl8.5
+    ${LOCALBASE}/include/tk8.5
+    ${LOCALBASE}/include/tcl8.4
+    ${LOCALBASE}/include/tk8.4
+    )
+endif()
 
 if(WIN32)
   set(TCLTK_POSSIBLE_INCLUDE_PATHS ${TCLTK_POSSIBLE_INCLUDE_PATHS}
